<template>
  <div id="actionNoticeTopSearch">
    <div class="search-box">
      <el-form
        ref="ruleForm"
        :inline="true"
        :model="formInline"
        class="demo-form-inline"
      >
        <el-form-item label="创建时间" prop="createTime">
          <el-date-picker
            v-model="formInline.createTime"
            type="datetimerange"
            range-separator="-"
            start-placeholder="开始时间"
            end-placeholder="结束时间"
            value-format="yyyy-MM-dd HH:mm:ss"
          ></el-date-picker>
        </el-form-item>
        <el-form-item label="触达通道" prop="touchType">
          <el-select
            v-model="formInline.touchType"
            clearable
            placeholder="请选择"
          >
            <el-option
              v-for="item in touchTypeList"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="审核状态" prop="auditingState">
          <el-select
            v-model="formInline.auditingState"
            clearable
            placeholder="请选择"
          >
            <el-option
              v-for="item in auditingStateList"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="提交状态" prop="submitState">
          <el-select
            v-model="formInline.submitState"
            clearable
            placeholder="请选择"
          >
            <el-option
              v-for="item in submitStateList"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="查询" prop="searchContent">
          <el-input
            clearable
            v-model="formInline.searchContent"
            placeholder="标题,通知ID查询"
          ></el-input>
        </el-form-item>
        <el-form-item class="s-btn">
          <el-button type="success" icon="el-icon-search" @click="toSearch()">
            查询
          </el-button>
          <el-button type="success" plain @click="reset">
            重置
          </el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>
<script>
import { sysNormalDisable } from '@utils/dictionariesFunc'
export default {
  name: 'ActionNoticeSearch',
  msg: '通知管理-顶部搜索',
  props: {
    formInline: {
      type: Object,
      default: function() {
        return {
          touchType: '',
          createTime: [],
          auditingState: '',
          submitState: '',
          startTime: '', // 开始时间
          endTime: '', // 结束时间,
          searchContent: ''
        }
      }
    }
  },
  data() {
    return {
      // 触达通道
      touchTypeList: [{ dictLabel: '全部', dictValue: '' }],
      // 审核状态列表
      auditingStateList: [{ dictLabel: '全部', dictValue: '' }],
      // 提交状态列表
      submitStateList: [{ dictLabel: '全部', dictValue: '' }],
      rules: {
        touchType: {},
        auditingState: {},
        submitState: {},
        search: {}
      },
      createTime: [] //  创建时间
    }
  },
  watch: {
    'formInline.createTime': {
      handler(newVal, oldVal) {
        if (newVal && newVal.length > 1) {
          this.formInline.startTime = newVal[0]
          this.formInline.endTime = newVal[1]
        } else {
          this.formInline.startTime = ''
          this.formInline.endTime = ''
        }
      },
      deep: true
    }
  },
  mounted() {
    this.getTopSearch()
  },
  methods: {
    /* 搜索 */
    toSearch() {
      this.$emit('toSearch')
    },
    /* 重置 */
    reset() {
      this.$refs['ruleForm'].resetFields()
    },
    // 获取顶部搜索条件
    async getTopSearch() {
      const touchTypeList = await sysNormalDisable(
        'activity_notice_type',
        'touchType'
      )
      this.touchTypeList = this.touchTypeList.concat(touchTypeList)
      // 审核状态
      const auditingStateList = await sysNormalDisable('activity_check_statu')
      this.auditingStateList = this.auditingStateList.concat(auditingStateList)
      // 提交状态
      const submitStateList = await sysNormalDisable('sys_submit_status')
      this.submitStateList = this.submitStateList.concat(submitStateList)
    }
  }
}
</script>

<style lang="less">
#actionNoticeTopSearch {
  .search-box {
    padding-left: 30px !important;
  }
}
</style>
